import java.util.Arrays;

/**
 * 274. H 指数
 * https://leetcode-cn.com/problems/h-index/
 */
public class Solutions_274 {
    public static void main(String[] args) {
//        int[] nums = {3, 0, 6, 1, 5};  // output: 3
//        int[] nums = {1};  // output: 1
        int[] nums = {100};  // output: 1

        int result = hIndex(nums);
        System.out.println(result);
    }

    public static int hIndex(int[] citations) {
        Arrays.sort(citations);
        int len = citations.length;
        for (int i = 0; i < len; i++) {
            int h = len - i;
            // 总共有 h 篇论文分别被引用了至少 h 次，而 [0, i - 1] 的论文，就是引用次数小于 h 次的
            if (h <= citations[i]) {
                return h;
            }
        }
        return 0;
    }
}
